package logic

import (
	"context"
	"doctor/models/mysql"
	"fmt"

	"doctor/doctorrpc/doctorrpc"
	"doctor/doctorrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type DoctorShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDoctorShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DoctorShowLogic {
	return &DoctorShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *DoctorShowLogic) DoctorShow(in *doctorrpc.DoctorShowRequest) (*doctorrpc.DoctorShowResponse, error) {
	// todo: add your logic here and delete this line
	var doctor mysql.Doctor
	err := mysql.DB.Debug().Where("id = ?", in.Id).Find(&doctor).Error
	if err != nil {
		return nil, fmt.Errorf("展示失败")
	}

	return &doctorrpc.DoctorShowResponse{
		Id:        int64(doctor.ID),
		Name:      doctor.Name,
		Headimage: doctor.Headimage,
		Hospatil:  doctor.Hospital,
		Rooms:     doctor.Rooms,
		Desc:      doctor.Desc,
	}, nil
}
